#include "../../../common/data_es.hpp"
#include <gflags/gflags.h>

DEFINE_bool(run_mode, false, "程序的运行模式, false-调试模式, true-发布模式");
DEFINE_string(log_file, "", "发布模式下, 用于指定日志文件的路径");
DEFINE_int32(log_level, 0, "发布模式下, 用于指定日志的输出等级");

DEFINE_string(es_host, "http://127.0.0.1:9200/", "es服务器URL");

int main(int argc, char* argv[]) 
{
    google::ParseCommandLineFlags(&argc, &argv, true);
    suye::Init_logger(FLAGS_run_mode, FLAGS_log_file, FLAGS_log_level);
    
    auto es_client = suye::ESClientFactory::create({FLAGS_es_host});
    auto es_message = std::make_shared<suye::ESMessage>(es_client);
    es_message->createIndex();
    // es_message->appendData("会话ID1", "消息ID1", "用户ID1", 1748694525, "吃饭了吗？");
    // es_message->appendData("会话ID1", "消息ID2", "用户ID2", 1748694525 - 100, "吃的盖浇饭！");
    // es_message->appendData("会话ID2", "消息ID3", "用户ID3", 1748694525, "昨天吃的什么？");
    // es_message->appendData("会话ID2", "消息ID4", "用户ID4", 1748694525 - 100, "昨天吃的泡面！");

    auto res = es_message->search("盖浇饭", "会话ID1");
    for (auto& m : res) {
        std::cout << "-----------------" << std::endl;
        std::cout << m.session_id() << std::endl;
        std::cout << m.message_id() << std::endl;
        std::cout << m.user_id() << std::endl;    
        std::cout << boost::posix_time::to_simple_string(m.create_time()) << std::endl;
        std::cout << m.content() << std::endl;
    }

    return 0;
}